public class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    //构造一个传入数组构建链表的方法
    public ListNode(int[] arr){
        if(arr.length == 0 || arr == null){
            throw new IllegalArgumentException("cannot create ListNode by Empty Array");
        }
        this.val = arr[0];
        ListNode cur = this;
        for(int i=1;i<arr.length;i++){
            ListNode node = new ListNode(arr[i]);
            cur.next = node;
            cur = cur.next;
        }
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("ListNode : ");
        ListNode cur = this;
        while(cur != null){
            sb.append(cur.val).append("->");
            cur = cur.next;
        }
        sb.append(" NULL");
        return sb.toString();
    }
}
